﻿using System.IO.IsolatedStorage;

namespace SilverBox.Helpers
{
    public class SettingsHelper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        public static void Set<T>(string propertyName, T? value) where T : struct
        {
            var settings = IsolatedStorageSettings.SiteSettings;
            if (settings.Contains(propertyName))
            {
                settings[propertyName] = value;
            }
            else
            {
                settings.Add(propertyName, value);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public static T? Get<T>(string propertyName) where T : struct
        {
            var settings = IsolatedStorageSettings.SiteSettings;
            if (settings.Contains(propertyName))
            {
                return (T?)settings[propertyName];
            }
            return null;
        }
    }
}